const baseUrl = "https://ffjzhfcapi.ffjzhfc.com"
// const baseUrl = "120.55.243.50:8090"
const api = (params) => {
	console.log(params);
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中',
		})
		uni.request({
			header: {
				'Content-Type': params.type || "application/json",
				'language': 'zh_CN',
				'X-Access-Token': uni.getStorageSync("accessToken") || ''
			},
			url: baseUrl + params.url,
			method: params.method || "GET",
			data: params.data || JSON.stringify(params.data),
			success: res => {
				console.log(res);
				uni.hideLoading()
				if (res.data.code == 200) {
					resolve(res.data)
				} else {
					uni.showToast({
						title: res.data.message,
						icon: 'error',
					})
					if (res.data.code == 401 || res.data.message == '未获取到用户') { //|| res.data.code == 500
						uni.navigateTo({
							url: "/pages/login/login"
						})
						uni.clearStorage();
						// localStorage.clear();
					}
				}
			}
		})
		// .then(res => {
		// 	console.log(res);
		// 	resolve(res);
		// }).catch(err => {
		// 	reject(err)
		// })
	})
}
export default {
	api,
	baseUrl
}